<?php

function databr($datasql) {
	if (!empty($datasql)){
	$p_dt = explode('-',$datasql);
	$data_br = $p_dt[2].'/'.$p_dt[1].'/'.$p_dt[0];
	return $data_br;
	}
}
function datasql($databr) {
	if (!empty($databr)){
	$p_dt = explode('/',$databr);
	$data_sql = $p_dt[2].'-'.$p_dt[1].'-'.$p_dt[0];
	return $data_sql;
	}
}

function subData($data1, $data2, $intervalo) {
    switch ($intervalo) {
        case 'y':
            $Q = 86400*365;
            break;
        case 'm':
            $Q = 2592000;
            break;
        case 'd':
            $Q = 86400;
            break;
        case 'h':
            $Q = 3600;
            break;
        case 'n':
            $Q = 60;
            break;
        default:
            $Q = 1;
            break;
    }
    return round((strtotime($data2) - strtotime($data1)) / $Q);
}

?>
